//
//  SDHSportsTeamInfoCell.m
//  SDHSportsNews
//
//  Created by MichaelShan on 2021/3/11.
//

#import "SDHSportsTeamInfoCell.h"
#import "SDHSportsTeamInfoModel.h"
#import "UIImageView+YQAdd.h"

@interface SDHSportsTeamInfoCell ()

@property (nonatomic, strong) UIImageView *avatarImg;
@property (nonatomic, strong) UILabel *nameLb;
@property (nonatomic, strong) UILabel *urlLb;
@property (nonatomic, strong) UILabel *timeLb;

@end

@implementation SDHSportsTeamInfoCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self initUI];
    }
    
    return self;
}

- (void)initUI {
    UIImageView *avatarImg = [UIImageView new];
    avatarImg.image = [UIImage imageNamed:@"touxiang"];
    [self.contentView addSubview:avatarImg];
    self.avatarImg = avatarImg;
    
    UILabel *nameLb = [UILabel new];
    nameLb.textAlignment = NSTextAlignmentLeft;
    nameLb.font = [UIFont boldSystemFontOfSize:16];
    nameLb.text = @"AC Milan";
    [self.contentView addSubview:nameLb];
    self.nameLb = nameLb;
    
    UILabel *urlLb = [UILabel new];
    urlLb.textAlignment = NSTextAlignmentLeft;
    urlLb.textColor = [UIColor blueColor];
    urlLb.font = [UIFont systemFontOfSize:14];
    urlLb.text = @"www.baidu.com";
    [self.contentView addSubview:urlLb];
    self.urlLb = urlLb;
    
    
    UILabel *timeLb = [UILabel new];
    timeLb.textAlignment = NSTextAlignmentRight;
    timeLb.textColor = [UIColor grayColor];
    timeLb.font = [UIFont systemFontOfSize:14];
    timeLb.text = @"2021-03-01";
    [self.contentView addSubview:timeLb];
    self.timeLb = timeLb;
    
    [self.avatarImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.centerY.mas_equalTo(self.contentView);
        make.width.equalTo(@(50));
        make.height.equalTo(@(50));
    }];
    
    [self.nameLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.avatarImg.mas_right).offset(10);
        make.centerY.equalTo(self.contentView).offset(-10);
    }];
    
    [self.urlLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLb);
        make.top.equalTo(self.nameLb.mas_bottom).offset(5);
    }];
    
    [self.timeLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView.mas_right).offset(-10);
        make.centerY.equalTo(self.contentView);
    }];
}

- (void)updateContent:(id)obj {
    SDHSportsTeamInfoModel *model = (SDHSportsTeamInfoModel *)obj;
    
    [self.avatarImg setImageWithURL:[NSURL URLWithString:model.logo] placeholderImage:[UIImage imageNamed:@"touxiang"]];
    self.nameLb.text = model.en_name;
    self.urlLb.text = model.web_site;
    self.timeLb.text = model.established_date;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
